|
|
|
|
|
|
|
The following code shows the Visual Basic definition of the BITMAPINFO and BITMAPINFOHEADER data structures. |
|
|
|
 |
|
|
|
|
Public Type BITMAPINFO
bmiHeader As BITMAPINFOHEADER
bmiColors(0 To 255) As RGBQUAD
End Type
Public Type BITMAPINFOHEADER
biSize As Long ' Size of BITMAPINFOHEADER biWidth As Long ' Width of bitmap. biHeight As Long ' Height of bitmap. biPlanes As Integer ' Must be 1. biBitCount As Integer ' Number of bits per pixel. biCompression As Long ' BI_RGB for no compression. biSizeImage As Long ' Size. Can be 0 if BI_RGB. biXPelsPerMeter As Long ' Resolution of target device. biYPelsPerMeter As Long ' Resolution of target device. biClrUsed As Long ' # colors in color table. biClrImportant As Long ' # required colors. End Type
Public Type RGBQUAD
rgbBlue As Byte
rgbGreen As Byte
rgbRed As Byte
rgbReserved As Byte
End Type |
|
|
|
|
|
|
|
|
The general steps for loading a DIB from a picture box are: |
|
|
|
|
|
|
|
|
1. Use the CreateCompatibleDC API function to create a device context (DC) in memory that is compatible with the picture box. |
|
|
|
|
|
|
|
|
2. Use the CreateCompatibleBitmap API function to create a bitmap in memory that is compatible with the picture box. |
|
|
|
|
|
|
|
|
3. Use the SelectObject API function to select the new bitmap into the new device context. |
|
|
|
|
|
|
|
|
4. If the picture box has a color depth of eight or less, it uses a color palette. Use the SelectPalette and RealizePalette API functions to select the palette into the new device context. |
|
|
|
|
|
|
|
|
5. Use BitBlt to copy the image from the picture box into the new device context. This puts a copy of the picture box's image in the new bitmap in memory. |
|
|
|
|
|
|
|
|
6. Use SelectObject to deselect the new bitmap from the new device context. The GetDIBits API function requires that the bitmap it uses not be selected in any device context. |
|
|
|
|
|
|
|
|
7. Initialize the biSize, biWidth, biHeight, biPlanes, biBitCount, and biCompression fields in a BITMAPINFO data structure to describe the new DIB. |
|
|
|
|
|